package view_manage

import (
	"time"
	"vrcm/src/vrcm/app/admin/models/view"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type ViewCheckGetPageReq struct {
	dto.Pagination `search:"-"`
	CheckInfo      string `json:"check_info"  search:"type:startswith;column:check_info;table:view_check"`
	IsDelete       int    `json:"is_delete"  search:"type:exact;column:is_delete;table:view_check"`
}

type ViewCheckOrder struct {
	Id         string `form:"idOrder"  search:"type:order;column:id;table:view_check"`
	ViewId     string `form:"viewIdOrder"  search:"type:order;column:view_id;table:view_check"`
	CheckInfo  string `form:"checkInfoOrder"  search:"type:order;column:check_info;table:view_check"`
	CreateTime string `form:"createTimeOrder"  search:"type:order;column:create_time;table:view_check"`
	IsDelete   string `form:"isDeleteOrder"  search:"type:order;column:is_delete;table:view_check"`
}

func (m *ViewCheckGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type ViewCheckInsertReq struct {
	Id         int         `json:"-" comment:""` //
	ViewId     int         `json:"view_id" comment:"观看id"  validate:"required"`
	CheckType  int         `json:"check_type" comment:"1 密码 3手机号 5观看码" validate:"required,gt=0"`
	LimitInfos []LimitInfo `json:"limit_infos" comment:"限制信息 密码 手机号 观看码等等"`
	common.ControlBy
	common.ModelTime
}

func (s *ViewCheckInsertReq) Generate(models *[]view.ViewCheck) {

	for _, v := range s.LimitInfos {
		model := view.ViewCheck{}
		if v.Id == 0 {
			model.CreateBy = s.CreateBy
			model.CreateTime = time.Now().Unix()
			model.UpdateTime = time.Now().Unix()
		} else {
			model.Id = v.Id
			model.CreateTime = v.CreateTime
			model.CreateBy = v.CreateBy
			model.UpdateBy = v.UpdateBy
			model.UpdateTime = time.Now().Unix()
		}
		model.IsSms = v.IsSms
		model.ViewId = s.ViewId
		model.CheckInfo = v.LimitInfo
		model.Account = v.Account
		model.UserName = v.UserName
		model.Desc = v.Desc
		model.IsDelete = 2
		model.CheckType = s.CheckType
		*models = append(*models, model)
	}
}

func (s *ViewCheckInsertReq) GetId() interface{} {
	return s.Id
}

type ViewCheckUpdateReq struct {
	Id        int    `uri:"id" comment:""` //
	ViewId    int    `json:"view_id" comment:"观看id"`
	CheckInfo string `json:"check_info" comment:"观看密码 或 手机号"`
	IsDelete  string `json:"is_delete" comment:"是否删除 1 删除"`
	CheckType int    `json:"check_type" comment:"1 密码 3手机号 5观看码" validate:"required,gt=0"`
	UserName  string `json:"user_name" comment:"用户名"`
	Account   string `json:"account" comment:"绑定账号"`
	Desc      string `json:"desc" comment:"描述"`
	IsSms     int    `json:"is_sms" comment:"是否短信验证 1 是 2否"`
	common.ControlBy
}

func (s *ViewCheckUpdateReq) Generate(model *view.ViewCheck) {

	model.ViewId = s.ViewId
	model.CheckInfo = s.CheckInfo
	model.Account = s.Account
	model.UserName = s.UserName
	model.Desc = s.Desc
	model.CreateTime = time.Now().Unix()
	model.CheckType = s.CheckType
	model.IsSms = s.IsSms
	model.UpdateTime = time.Now().Unix()
	model.UpdateBy = s.UpdateBy
}

func (s *ViewCheckUpdateReq) GetId() interface{} {
	return s.Id
}

// ViewCheckGetReq 功能获取请求参数
type ViewCheckGetReq struct {
	Id     int `uri:"id"`
	ViewId int `json:"view_id"`
}

func (s *ViewCheckGetReq) GetId() interface{} {
	return s.Id
}

// ViewCheckDeleteReq 功能删除请求参数
type ViewCheckDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *ViewCheckDeleteReq) GetId() interface{} {
	return s.Ids
}

type ResetViewCodeReq struct {
	Id        int `json:"-" comment:""` //
	ViewId    int `json:"view_id" comment:"观看id"  validate:"required"`
	CheckType int `json:"check_type" comment:"1 密码 3手机号 5观看码" validate:"required,gt=0"`
	common.ControlBy
	common.ModelTime
}

type UpdateJoinTimeReq struct {
	ViewId    int    `json:"view_id" comment:"观看id"  validate:"required"`
	CheckInfo string `json:"check_info" comment:"观看密码 或 手机号" validate:"required"`
	CheckType int    `json:"check_type" comment:"1 密码 3手机号 5观看码" validate:"required,gt=0"`
	UserName  string `json:"user_name" comment:"用户名"`
	Account   string `json:"account" comment:"绑定账号"`
	common.ControlBy
}

type GetViewCodeDetailReq struct {
	ViewId    int `json:"view_id" comment:"观看id"  validate:"required"`
	CheckType int `json:"check_type" comment:"1 密码 3手机号 5观看码" validate:"required,gt=0"`
}

type GetViewCodeDetailRes struct {
	ViewId     int `json:"view_id" comment:"观看id" `
	CheckType  int `json:"check_type" comment:"1 密码 3手机号 5观看码"`
	TotalNum   int `json:"total_num" comment:"总数"`
	InvalidNum int `json:"invalid_num" comment:"失效数"`
	BindNum    int `json:"bind_num" comment:"绑定数"`
	UnUseNum   int `json:"un_use_num" comment:"未使用数"`
}
